home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3475 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  92 lines

  1. Path: oasis.novia.net!not-for-mail
  2. From: tsyslo@oasis.novia.net (Tony Syslo)
  3. Newsgroups: comp.lang.c
  4. Subject: New C Programmer Has A Problem
  5. Date: 29 Jan 1996 06:26:10 GMT
  6. Organization: Novia Internetworking <> 28.8kbps dialup; 402/390-2NET
  7. Message-ID: <4ehpa3$6kl@nntp.novia.net>
  8. NNTP-Posting-Host: oasis.novia.net
  9. X-Newsreader: TIN [UNIX 1.3 BETA-950824-color PL0]
  10.  
  11.  
  12.  START MESSAGE:
  13.  
  14.  
  15.   I have a question on C... why isn't this program working?!
  16.   
  17.   Program START:
  18.   /* File Open */
  19.   
  20.   #include <clib/dos_protos.h>
  21.   #include <dos/dos.h>
  22.   #include <stdio.h>
  23.   #include <exec/types.h>
  24.   
  25.   void main();
  26.   
  27.     char *name;
  28.     int age;
  29.             
  30.   void main()
  31.   
  32.   {
  33.     struct FileHandle *file_handle;
  34.     long bytes_written;
  35.     long bytes_read;
  36.   
  37.    printf("Enter your name: ");
  38.    scanf("%s",name);
  39.    printf("\nEnter your age: ");  scanf("%d",age);
  40.   
  41.   
  42.     file_handle=(struct FileHandle *)
  43.       Open("RAM:You.dat",MODE_NEWFILE);
  44.     /* Have we opened the file successfully? */
  45.     if(file_handle==NULL)
  46.     {
  47.       printf("Could not open the file!\n");
  48.       Exit(0);
  49.     }
  50.     /* We have now opened a file, and are ready to start writing: */
  51.     bytes_written=Write(file_handle,name,sizeof(name));
  52.     bytes_written=bytes_written+Write(file_handle,age,sizeof(age));
  53.   
  54.     if(bytes_written!=sizeof(name)+sizeof(age))
  55.     {
  56.       printf("Could not save the list!\n");
  57.       Close(file_handle);
  58.       Exit(0);
  59.     }
  60.     else
  61.       printf("Saved successfully!\n");
  62.     printf("Memory cleared!\n");
  63.      name="";
  64.      age=0;
  65.     printf("Loading!\n");
  66.     Seek(file_handle,0,OFFSET_BEGINNING);
  67.     bytes_read=Read(file_handle,name,sizeof(name));
  68.     bytes_read=bytes_read+Read(file_handle,age,sizeof(age));
  69.     if(bytes_written!=sizeof(name)+sizeof(age))
  70.     {
  71.       printf("Could not read the list!\n");
  72.       Close(file_handle);
  73.       Exit(0);
  74.     }
  75.     /* Print out the data: */
  76.       printf("Hello, %s!\",name);
  77.       printf("You are %d years old!\n",age);
  78.     /* Close the file: */
  79.     Close(file_handle);
  80.   }
  81.   
  82.   Program END:
  83.   
  84.   Any help if MUCH appreciated...
  85.  
  86.  I am using the SAS/C 6.50 compiler...
  87.        
  88.   Also, is there any of you whom might have a routine to figure up random (or
  89.   even psuedo-random) numbers?? Some algorithm, or such, as I need one BADLY!!
  90.   
  91.  MESSAGE END:
  92.